﻿//********************************************************************************//
//创建日期：<创建日期，2016-02-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：自来水公司数据设置
//********************************************************************************//

using System;
using System.Web.UI;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui.JiChuXX
{
    public partial class ZiLaisgssjsz : BasePage
    {
        #region 属性

        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int ZiLaiSGSSJSZID
        {
            get
            {
                return Convert.ToInt32(ViewState["_ZiLaiSGSSJSZID"]);
            }
            set
            {
                ViewState["_ZiLaiSGSSJSZID"] = value;
            }
        }
        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }
       
        #endregion

        #region 变量
        
        /// <summary>
        /// 自来水公司数据设置对象
        /// </summary>
        YS_JX_ZILAISGSSJSZ _YS_JX_ZILAISGSSJSZ = new YS_JX_ZILAISGSSJSZ();

        /// <summary>
        /// 自来水公司数据设置BLL
        /// </summary>
        YS_JX_ZILAISGSSJSZBLL _YS_JX_ZILAISGSSJSZBLL = new YS_JX_ZILAISGSSJSZBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        #endregion

        #region 事件

       /// <summary>
       /// 页面加载事件
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitControl();
                InitData();             
            }
            LoadData();
        }

        /// <summary>
        /// 绑定空表头
        /// </summary>
        /// <param name="sender"></param>
        protected override void Render(HtmlTextWriter sender)
        {
            //绑定空表头
            base.Render(sender);
        }  
        
        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "info")
            {
                this._YS_JX_ZILAISGSSJSZ = this._YS_JX_ZILAISGSSJSZBLL.SelectYS_JX_ZILAISGSSJSZ(id);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                cr.AddValue(this._YS_JX_ZILAISGSSJSZ.S_MINGCHENG, this._YS_JX_ZILAISGSSJSZ.S_GUANLIKBH, this._YS_JX_ZILAISGSSJSZ.S_SUOSHUSF, this._YS_JX_ZILAISGSSJSZ.S_WENJIANMMGZ);
                e.Result = cr.ToString();
                return;
            }
            else if (e.Parameter == "del")
            {
                //执行逻辑删除
                this._YS_JX_ZILAISGSSJSZ = this._YS_JX_ZILAISGSSJSZBLL.SelectYS_JX_ZILAISGSSJSZ(id);
                this._YS_JX_ZILAISGSSJSZ.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                this._YS_JX_ZILAISGSSJSZ.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                this._YS_JX_ZILAISGSSJSZ.I_JLZT = -1;
                _SYS_LOGBLL.Log<YS_JX_ZILAISGSSJSZ>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "自来水公司数据设置", OperateState.Delete, _YS_JX_ZILAISGSSJSZ, null);
                if (_YS_JX_ZILAISGSSJSZBLL.InsertOrUpdate(_YS_JX_ZILAISGSSJSZ))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "操作成功！";
                    e.Result = cr.ToString();
                    return;
                }
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;
                //添加
                if (id == -1)
                {
                    this._YS_JX_ZILAISGSSJSZ.ID = 0;
                    _YS_JX_ZILAISGSSJSZ.I_JLZT = 0;
                    operateState = OperateState.Add;
                }
                //修改
                else
                {
                    //修改操作
                    _YS_JX_ZILAISGSSJSZ = this._YS_JX_ZILAISGSSJSZBLL.SelectYS_JX_ZILAISGSSJSZ(id);
                    operateState = OperateState.Modify;
                }
                //判断名称是否重复
                if (_YS_JX_ZILAISGSSJSZBLL.SelectYS_JX_ZILAISGSSJSZsDynamic(string.Format("S_MINGCHENG='{0}' and ID<>{1}", this.txtMINGCHENG.Text, _YS_JX_ZILAISGSSJSZ.ID), null).Rows.Count > 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "你所输入的编号,系统中已经存在使用过,请修改！";
                    e.Result = cr.ToString();
                    return;
                }
                _YS_JX_ZILAISGSSJSZ.S_MINGCHENG = this.txtMINGCHENG.Text;
                _YS_JX_ZILAISGSSJSZ.S_WENJIANMMGZ = this.txtWENJIANMMGZ.Text;
                _YS_JX_ZILAISGSSJSZ.S_GUANLIKBH = Convert.ToString(this.ddlGUANLIK.Value);
                _YS_JX_ZILAISGSSJSZ.S_SUOSHUSF = Convert.ToString(this.ddlSUOSHUSF.Text);
                //设置操作信息
                this._YS_JX_ZILAISGSSJSZ.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                this._YS_JX_ZILAISGSSJSZ.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                //执行操作
                _SYS_LOGBLL.Log<YS_JX_ZILAISGSSJSZ>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "自来水公司数据设置", operateState, _YS_JX_ZILAISGSSJSZ, null);
                if (_YS_JX_ZILAISGSSJSZBLL.InsertOrUpdate(_YS_JX_ZILAISGSSJSZ))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "保存成功！";
                    cr.SpecialIndetity = _YS_JX_ZILAISGSSJSZ.ID.ToString();
                    e.Result = cr.ToString();
                    return;
                }
            }
        }

        /// <summary>
        /// 回调数据加载
        /// </summary>
        protected void gvList_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            LoadData();
        }
       
        #endregion

        #region 方法

        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitControl()
        {
            //加载所属算法
            WordsManager manger = new WordsManager();
            PageTools.BindComboBox(ddlSUOSHUSF, manger.Instance.FindWordsDataTableByBelongID(WordsStruct.BelongID.所属算法));
            //加载管理块
            PageTools.BindComboBox(ddlGUANLIK,BusinessTool.GetTextAndValue("YS_JX_GUANLIK","S_GUANLIKMC","S_GUANLIKH",null,null).Tables[0]);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData()
        {
            this.gvList.DataSource = _spHelper.P_VIEW_YS_ZILAISGSSJSZ().Tables[0];
            this.gvList.DataBind();
        }

        #endregion
    }
}